package com.test.encprytool;

import java.util.Random;

/**
 * 随机生成混淆字典工具类
 * Created by xxj on 2018/7/2.
 */

public class ProguardDictionaryTool {

    private final static String ALL_STR_DIR = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private final static int MINI_CHAR_LENGTH = 1;
    private final static int MAX_CHAR_LENGTH = 3;
    private final static int MAX_DIR_LENGTH = 400;

    public static void main(String[] args) throws Exception {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < MAX_DIR_LENGTH; i++) {
            stringBuffer.append(getRandomString(new Random().nextInt(MAX_CHAR_LENGTH) + MINI_CHAR_LENGTH) + '\n');
        }
        EncryptTool.writeFile("proguard_dic.txt", stringBuffer.toString());
    }

    public static String getRandomString(int length) {
        int strDirLength = ALL_STR_DIR.length();
        Random random = new Random();
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < length; i++) {
            int number = random.nextInt(strDirLength);
            while (i==0 && number < 10){
                //保证第一位不是数字
                number = random.nextInt(strDirLength);
            }
            sb.append(ALL_STR_DIR.charAt(number));
        }
        return sb.toString();
    }

}
